package net.demo.demo1;

import java.io.IOException;
import java.net.*;
import java.util.Date;
import java.util.Scanner;

public class Udpreceive {
    public static void main(String[] args) throws IOException {
        DatagramSocket ds = new DatagramSocket(10086);

        byte[] bytes=new byte[1024];
        DatagramPacket dp=new DatagramPacket(bytes,bytes.length);

        while (true){
            ds.receive(dp);
            byte[] data = dp.getData();
            String ip = dp.getAddress().getHostAddress();
            String name = dp.getAddress().getHostName();
            int length = dp.getLength();

            System.out.println("ip为:"+ip+"名字为:"+name+"信息:"+new String(data,0,length));
        }
    }
}
